package product;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.HashMap;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;

public class HolyReason extends JInternalFrame {

	PreparedStatement pstmt;
	String userid = "";
	String holydate = "";

	Connection conn;
	ProductMain3 pm;
	MemberHoly mh;

	private JPanel contentPane;
	private JPanel panel;
	private JPanel panel_1;
	private JLabel label;
	private JLabel label_1;
	private JScrollPane scrollPane;
	private JLabel label_3;
	private JScrollPane scrollPane_1;
	private JLabel label_4;
	private JScrollPane scrollPane_2;
	private JLabel lblNewLabel;
	JTextArea accident;
	JTextArea reason;
	JTextArea result;
	private JButton btnNewButton;
	private JButton btnNewButton_1;
	private JTextField pg;

	public HolyReason(Connection conn, ProductMain3 pm) { // 매개변수

		super("사유서 보기",true,true,true,false);
		this.conn=conn;
		this.pm=pm;
		
		

		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setBounds(100, 100, 478, 367);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		contentPane.add(getPanel(), BorderLayout.SOUTH);
		contentPane.add(getPanel_1(), BorderLayout.CENTER);


	}
	

	public void setH(MemberHoly mh){
		this.mh=mh;
	}
	
	public void reasoneditor(){


		try{
			int yn = -1;
				yn = JOptionPane.showConfirmDialog(null, "승인 하시겠습니까?");
				if(yn == JOptionPane.YES_OPTION){
					String sql = "update holydata set holytype=?, info=? where memberid=? and holydate=?";
					
					
					pstmt = conn.prepareStatement(sql);

					pstmt.setString(1, "4");
					pstmt.setString(2, "승인                     %" + accident.getText() + "%" + reason.getText() + "%" + result.getText());
					pstmt.setString(3, userid);
					pstmt.setString(4, holydate);

					pstmt.executeUpdate();

					pstmt.close();


					JOptionPane.showMessageDialog(null, "승인 되었습니다");
				}
		}catch(Exception e){
			e.printStackTrace();
		}

	}
	public void reasoncancel(){
		

			try{
				int yn = -1;
					yn = JOptionPane.showConfirmDialog(null, "승인거부 하시겠습니까?");
					if(yn == JOptionPane.YES_OPTION){
						
						String sql = "update holydata set holytype=?, info=? where memberid=? and holydate=?";

						pstmt = conn.prepareStatement(sql);

						pstmt.setString(1, "0");
						pstmt.setString(2, "사유서결격                     %" + accident.getText() + "%" + reason.getText() + "%" + result.getText());
						pstmt.setString(3, userid);
						pstmt.setString(4, holydate);

						pstmt.executeUpdate();

						pstmt.close();


						JOptionPane.showMessageDialog(null, "승인 거부 되었습니다.");
					}
			}catch(Exception e){
				e.printStackTrace();
			}

	}


	public void setData(String code, String nal, String rs){

		this.userid=code;
		this.holydate=nal;
		
		String[] hyrn = rs.split("%");
		System.out.println(hyrn);
		accident.setText(hyrn[1]);
		reason.setText(hyrn[2]);
		result.setText(hyrn[3]);
		pg.setText(hyrn[0]);
	}

	private JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setPreferredSize(new Dimension(10, 30));
			panel.add(getPg());
			panel.add(getBtnNewButton());
			panel.add(getBtnNewButton_1());
		}
		return panel;
	}
	private JPanel getPanel_1() {
		if (panel_1 == null) {
			panel_1 = new JPanel();
			GridBagLayout gbl_panel_1 = new GridBagLayout();
			gbl_panel_1.columnWidths = new int[]{0, 0, 0};
			gbl_panel_1.rowHeights = new int[]{0, 0, 0, 0, 0};
			gbl_panel_1.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
			gbl_panel_1.rowWeights = new double[]{0.0, 1.0, 1.0, 1.0, Double.MIN_VALUE};
			panel_1.setLayout(gbl_panel_1);
			GridBagConstraints gbc_label = new GridBagConstraints();
			gbc_label.fill = GridBagConstraints.BOTH;
			gbc_label.insets = new Insets(0, 0, 5, 5);
			gbc_label.gridx = 0;
			gbc_label.gridy = 0;
			panel_1.add(getLabel(), gbc_label);
			GridBagConstraints gbc_label_1 = new GridBagConstraints();
			gbc_label_1.insets = new Insets(0, 0, 5, 0);
			gbc_label_1.gridx = 1;
			gbc_label_1.gridy = 0;
			panel_1.add(getLabel_1(), gbc_label_1);
			GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
			gbc_lblNewLabel.fill = GridBagConstraints.VERTICAL;
			gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
			gbc_lblNewLabel.gridx = 0;
			gbc_lblNewLabel.gridy = 1;
			panel_1.add(getLblNewLabel(), gbc_lblNewLabel);
			GridBagConstraints gbc_scrollPane = new GridBagConstraints();
			gbc_scrollPane.fill = GridBagConstraints.BOTH;
			gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
			gbc_scrollPane.gridx = 1;
			gbc_scrollPane.gridy = 1;
			panel_1.add(getScrollPane(), gbc_scrollPane);
			GridBagConstraints gbc_label_3 = new GridBagConstraints();
			gbc_label_3.fill = GridBagConstraints.BOTH;
			gbc_label_3.insets = new Insets(0, 0, 5, 5);
			gbc_label_3.gridx = 0;
			gbc_label_3.gridy = 2;
			panel_1.add(getLabel_3(), gbc_label_3);
			GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints();
			gbc_scrollPane_1.fill = GridBagConstraints.BOTH;
			gbc_scrollPane_1.insets = new Insets(0, 0, 5, 0);
			gbc_scrollPane_1.gridx = 1;
			gbc_scrollPane_1.gridy = 2;
			panel_1.add(getScrollPane_1(), gbc_scrollPane_1);
			GridBagConstraints gbc_label_4 = new GridBagConstraints();
			gbc_label_4.fill = GridBagConstraints.BOTH;
			gbc_label_4.insets = new Insets(0, 0, 0, 5);
			gbc_label_4.gridx = 0;
			gbc_label_4.gridy = 3;
			panel_1.add(getLabel_4(), gbc_label_4);
			GridBagConstraints gbc_scrollPane_2 = new GridBagConstraints();
			gbc_scrollPane_2.fill = GridBagConstraints.BOTH;
			gbc_scrollPane_2.gridx = 1;
			gbc_scrollPane_2.gridy = 3;
			panel_1.add(getScrollPane_2(), gbc_scrollPane_2);
		}
		return panel_1;
	}
	private JLabel getLabel() {
		if (label == null) {
			label = new JLabel("");
			label.setPreferredSize(new Dimension(80, 0));
		}
		return label;
	}
	private JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("내용");
		}
		return label_1;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setPreferredSize(new Dimension(80, 100));
			scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
			scrollPane.setViewportView(getAccident());
		}
		return scrollPane;
	}
	private JLabel getLabel_3() {
		if (label_3 == null) {
			label_3 = new JLabel("사유");
			label_3.setPreferredSize(new Dimension(0, 60));
			label_3.setHorizontalAlignment(SwingConstants.CENTER);
			label_3.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		}
		return label_3;
	}
	private JScrollPane getScrollPane_1() {
		if (scrollPane_1 == null) {
			scrollPane_1 = new JScrollPane();
			scrollPane_1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
			scrollPane_1.setViewportView(getTextArea_3());
		}
		return scrollPane_1;
	}
	private JLabel getLabel_4() {
		if (label_4 == null) {
			label_4 = new JLabel("처리");
			label_4.setPreferredSize(new Dimension(0, 60));
			label_4.setHorizontalAlignment(SwingConstants.CENTER);
			label_4.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		}
		return label_4;
	}
	private JScrollPane getScrollPane_2() {
		if (scrollPane_2 == null) {
			scrollPane_2 = new JScrollPane();
			scrollPane_2.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
			scrollPane_2.setViewportView(getTextArea_1_1());
		}
		return scrollPane_2;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("사고");
			lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
			lblNewLabel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
			lblNewLabel.setPreferredSize(new Dimension(80, 0));
		}
		return lblNewLabel;
	}
	private JTextArea getAccident() {
		if (accident == null) {
			accident = new JTextArea();
			accident.setEnabled(false);
		}
		return accident;
	}
	private JTextArea getTextArea_3() {
		if (reason == null) {
			reason = new JTextArea();
			reason.setEnabled(false);
		}
		return reason;
	}
	private JTextArea getTextArea_1_1() {
		if (result == null) {
			result = new JTextArea();
			result.setEnabled(false);
		}
		return result;
	}
	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("승인");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {


					reasoneditor();



				}
			});
		}
		return btnNewButton;
	}
	private JButton getBtnNewButton_1() {
		if (btnNewButton_1 == null) {
			btnNewButton_1 = new JButton("승인취소");
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {

					reasoncancel();


				}
			});
		}
		return btnNewButton_1;
	}

	private JTextField getPg() {
		if (pg == null) {
			pg = new JTextField();
			pg.setEnabled(false);
			pg.setHorizontalAlignment(SwingConstants.CENTER);
			pg.setColumns(10);
		}
		return pg;
	}
}
